import React, { useRef, useState } from 'react';
import { PlusOutlined, EllipsisOutlined } from '@ant-design/icons';
import {
  Button,
  Modal,
  Form,
  Input,
  DatePicker,
  Divider,
  message,
  Select,
  Popconfirm,
  InputNumber,
} from 'antd';
import type { ActionType } from '@ant-design/pro-table';
import ProTable from '@ant-design/pro-table';
import locale from 'antd/es/date-picker/locale/zh_CN';
import { motifColumns } from './data';
import type { MotifItem, customerListItem } from './data';
import TableTitle from '@/components/TableTitle';
import { getMotionList } from './service';
import moment from 'moment';
import { getLocalStorageInfo } from '@/utils/localStorageInfo';

export function formatWan(val: number) {
  const v = val * 1;
  if (!v || Number.isNaN(v)) return '';

  let result: React.ReactNode = val;
  if (val > 10000) {
    result = (
      <span>
        {Math.floor(val / 10000)}
        <span
          style={{
            position: 'relative',
            top: -2,
            fontSize: 14,
            fontStyle: 'normal',
            marginLeft: 2,
          }}
        >
          万
        </span>
      </span>
    );
  }
  return result;
}

const DaoProposal: React.FC = () => {
  // 绑定表格
  const actionRef = useRef<ActionType>();
  return (
    <ProTable<MotifItem>
      headerTitle={<TableTitle title="提案列表" />}
      // 搜索框配置
      search={false}
      scroll={{ x: 900 }}
      columns={motifColumns}
      actionRef={actionRef}
      cardBordered
      bordered
      rowKey="serialNo"
      dateFormatter="string"
      columnsState={{
        persistenceKey: 'motif-table',
        persistenceType: 'localStorage',
      }}
      // 分页相关配置
      pagination={{
        // 初始页面数据条数
        pageSize: 10,
      }}
      // 请求获取的数据
      request={async (params) => {
        console.log(params);

        let res = await getMotionList({ ...params });
        console.log(res);
        console.log('🎉');
        const result = {
          data: res.data,
          total: res.pagination.totalSize,
        };
        return result;
      }}
    />
  );
};

export default DaoProposal;
